import json
import re
import sys
import time
import requests
from bs4 import BeautifulSoup
import csv

headers = {
	"Host": "q.10jqka.com.cn",
	"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
	"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
	"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
	"Accept-Encoding": "gzip, deflate",
	"Referer": "http://q.10jqka.com.cn/gn/",
	"Connection": "keep-alive",
	"Cookie": "Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1639551899; v=A9EFgnPdVFnLYrhNtQSqJ8Sp4NxrPkWw77LpxLNmzRi3Wv8M-45VgH8C-ZhA; log=; Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1639552294; historystock=300603; spversion=20130314; searchGuide=sg",
	"Upgrade-Insecure-Requests": "1",
	"Pragma": "no-cache",
	"Cache-Control": "no-cache"
}

def get_gainian_code_name():
	url = 'http://q.10jqka.com.cn/gn/detail/code/308801/'
	res = requests.get(url, timeout=10, headers=headers).text
	# print(res)
	soup = BeautifulSoup(res, 'lxml')
	# print(soup)
	content = soup.findAll('a', target="_blank", href=re.compile("http://q.10jqka.com.cn/gn/detail/code/*"))
	# print(content)

	code = []
	title = []
	for c in content:
		# print(c.get("href"), c.text)
		code.append(c.get("href").split('/')[-2])
		title.append(c.text)
	return code, title

if __name__ == '__main__':
	code, name = get_gainian_code_name()
	print(code)
	for c in code:
		print(c)